package com.aramis.mydytt.ui.detail

import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.aramis.mydytt.R
import com.aramis.mydytt.ext.getFriendlyTimeStr
import com.aramis.mydytt.ui.base.BaseViewHolder
import com.aramis.mydytt.ui.base.SimpleRecyclerAdapter
import com.aramis.mydytt.ui.bean.MovieCommentBean
import com.facebook.drawee.view.SimpleDraweeView

/**
 * Description: MovieCommentAdapter
 * @author lizhidan
 * Created: 2021/5/10
 */
class MovieCommentAdapter : SimpleRecyclerAdapter<MovieCommentBean, MovieCommentAdapter.ViewHolder>() {

    inner class ViewHolder(parent: ViewGroup) : BaseViewHolder<MovieCommentBean>(parent, R.layout.item_detail_comment) {
        private val avatarView: SimpleDraweeView = itemView.findViewById(R.id.image_comment_avatar)
        private val nicknameView: TextView = itemView.findViewById(R.id.text_comment_nickname)
        private val contentView: TextView = itemView.findViewById(R.id.text_comment_content)
        private val timeView: TextView = itemView.findViewById(R.id.text_comment_time)
        private val thumbNumView: TextView = itemView.findViewById(R.id.text_comment_thumb_num)
        private val lineView: View = itemView.findViewById(R.id.line_comment_bottom)

        override fun bind(m: MovieCommentBean, position: Int) {
            avatarView.setImageURI(m.avatar)
            nicknameView.text = m.nickname
            contentView.text = m.content
            thumbNumView.text = m.thumb_num.toString()
            lineView.visibility = if (position < dataList.size - 1) View.VISIBLE else View.INVISIBLE
            timeView.text = getFriendlyTimeStr(m.time ?: "")
        }

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(parent)
    }

}